import { Module, Global } from '@nestjs/common';
import { RedisService } from './redis.service';
import { createClient } from "redis";

@Global()
@Module({
  providers: [
    RedisService,
    {
      provide: 'REDIS_CLIENT',
      async useFactory() {
        const client = createClient({
          socket: {
            host: '192.168.56.101',
            port: 6379
          },
          // database 就是把存储的 key-value 的数据放到不同命名空间下，避免冲突
          database: 2
        });
        await client.connect();

        return client;
      }
    }
  ],
  exports: [RedisService]
})
export class RedisModule { }
